
/**
 * 
 * 
 * 
 */

//require express
const express = require('express')
//require user module
const userRouter = require('./routes/user.js')
//require mysql
const mysql = require('mysql')

//create server
const app = express();
//set port
app.listen(8888, (req, res) => {
  console.log("8888ok")
})

//Use middleware to parse the data requested by post into objects
app.use(express.urlencoded({
  extended: false
}))


app.all('/', function (req, res) {
  res.sendFile(__dirname + "/public" + "/login.html");
})
app.use(express.static('./public'))


//Using a router, mount the router under the web server
//Prefix all routes '/v1/users'
app.use('/v1/users', userRouter)

//Add error handling middleware to intercept errors in all routes
app.use((err, req, res, next) => {
  //Accept the error message passed by the route
  console.log(err)
  //corresponding error
  res.status(500).send('msg:server error')
})







